<?php
/**
 * @orm tablename nodes
 */
class Node extends DomArObject {
	
	/**
	 * @orm char(255)
	 */
	public $name;
	/**
	 * @orm text
	 */
	public $comment;
	/**
	 * @orm has parent Node inverse children
	 * @orm listener afterSet afterSetParent
	 */
	public $parent;
	/**
	 * @orm owns children Node inverse parent
	 */
	public $children;
	/**
	 * @orm plugin SimpleOrder(parent)
	 */
	public $order;
	/**
	 * @orm has child Element inverse node
	 * @orm listener afterSet afterSetElement
	 */
	public $element;
	/**
	 * @orm char(255)
	 */
	public $elementClassName;
	/**
	 * @orm char(255)
	 */
	public $parents;
	/**
	 * @orm int(11)
	 */
	public $level = 0;
	
	/**
	 * These objects are related to this Node as children.
	 * @orm owns children NodeLink inverse parent
	 */
	public $fosterChildren;
	/**
	 * These objects are related to this Node as parents. They usually don't affect this Node.
	 * @orm has children NodeLink inverse child
	 */
	public $fosterParents;
	
	
	public function afterSetParent() {
		$this->parents = $this->parent->id.'/';
		$this->level = substr_count($this->parents,'/');
	}
	
	public function afterSetElement() {
		$this->elementClassName = get_class($this->element);
	}

}

/**
 * @orm tablename relations
 */
class NodeLink extends DomArObject {
	
	/**
	 * @orm has parent Node inverse fosterChildren
	 */
	public $parent;
	/**
	 * @orm has parent Node inverse fosterParents
	 */
	public $child;
	/**
	 * @orm char(255)
	 */
	public $key;
	
}

/**
 * 
 */
abstract class Element extends DomArObject {
	
	/**
	 * @orm has parent Node inverse element
	 */
	public $node;
	
}



/**
 * @orm tablename documents
 */
class Document extends Element {
	
	/**
	 * @orm char(255)
	 */
	public $title;
	/**
	 * @orm longtext
	 */
	public $summary;
	/**
	 * @orm longtext
	 */
	public $contents;
	
}
?>